package sws.alex.run;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public abstract class Layer {
	int x,y;
	int width,height;
	boolean visible = true;
	
	public Layer(int width, int height) {
		setWidthImpl(width);
        setHeightImpl(height);
	}

	public void setPosition(int x,int y){
		this.x = x;
		this.y = y;
	}

	public void setPosition(float x,float y){
		setPosition((int)x,(int)y);
	}
	
	public void move(int dx,int dy){
		this.x+=dx;
		this.y+=dy;
	}
	
	public void move(float dx,float dy){
		move((int)x,(int)y);
	}
	
	public abstract void paint(Canvas c);
	
	public void drawBitmap(Canvas c,int x,int y,Bitmap src,int sx,int sy,
			int w,int h){
		Rect rectSrc = new Rect();
		rectSrc.left = sx;
		rectSrc.right = sx + w;
		rectSrc.top = sy;
		rectSrc.bottom = sy + h;
		
		Rect rectDest = new Rect();
		rectDest.left = x;
		rectDest.right = x + w;
		rectDest.top = y;
		rectDest.bottom = y + h;

		c.drawBitmap(src,rectSrc,rectDest,null);
	}
	
	public int getX(){
		return this.x;
	}
	
	public void setX(int x){
		this.x = x;
	}
	
	public int getY(){
		return this.y;
	}
	
	public void setY(int y){
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean isVisible) {
		this.visible = isVisible;
	}	

    void setWidthImpl(int width) {
        if (width < 0) {
            throw new IllegalArgumentException();
        }
        this.width = width;
    }
	
    void setHeightImpl(int height) {
        if (height < 0) {
            throw new IllegalArgumentException();
        }
        this.height = height;
    }
}
